﻿using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class Card : MonoBehaviour, IPointerClickHandler
{
    public int id = -1;
    public Rect rect;
    public CardType cardType;
    public List<int> block = new List<int>(); //挡住了哪些卡片
    public List<int> blocked = new List<int>(); //被哪些卡片挡住了
    public void Init()
    {
        GetComponent<Image>().color = cardType.color;
        UpdateGray();
    }

    public void UpdateGray()
    {
        transform.Find("Mask").gameObject.SetActive(blocked.Count > 0);
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        if (blocked.Count <= 0)
        {
            foreach (int cardId in block)
            {
                Card blockedCard = Game.CardsMap[cardId];
                blockedCard.blocked.Remove(id);
                blockedCard.UpdateGray();
            }

            Game.CardsMap.Remove(id);
            Destroy(gameObject);    
        }
    }
}
